package com.yixing.tech.common.base;

import org.bson.Document;
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;

import java.util.List;

public class CustomAggregationOperation implements AggregationOperation {

    String sql;

    public CustomAggregationOperation(String sql) {
        this.sql = sql;

    }

    @Override
    public Document toDocument(AggregationOperationContext context) {
        return context.getMappedObject(Document.parse(sql));
    }

    @Override
    public List<Document> toPipelineStages(AggregationOperationContext context) {
        return AggregationOperation.super.toPipelineStages(context);
    }

    @Override
    public String getOperator() {
        return AggregationOperation.super.getOperator();
    }
}
